// JSON Java Class Generator
// Written by Bruce Bao
// Used for API: http://www.weather.com.cn/data/sk/101010100.html
package com.dex4d.model;

import com.dex4d.constants.AppConstants;
import com.dex4d.utils.BaseUtils;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.List;

public class User implements Serializable, Cloneable {
	/**
	 * @Fields: serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	private static User instance;

	private User() {

	}
	public final static String TAG = "User";
	private String userName;
	private boolean loginStatus;

	private String walletName;
	private String address;
	private String keystore;
	private String passphrase;
	private String pinCode;
	private List<String> mnemonic;
	private boolean isBackup;
	private String referralAddress; //别人的推荐地址（购买的时候需要使用，给予对方返利）
	private String myReferralAlias; //我的推荐别名（自己的）

	public static User getInstance() {
		if (instance == null) {
			Object object = BaseUtils.restoreObject(AppConstants.CACHEDIR + TAG);
			if (object == null) { // App第一次启动，文件不存在，则新建之
				object = new User();
				BaseUtils.saveObject(AppConstants.CACHEDIR + TAG, object);
			}

			instance = (User) object;
		}

		return instance;
	}


	
	public void reset() {
		userName = null;
		loginStatus = false;
	}
	
	public void save() {
		BaseUtils.saveObject(AppConstants.CACHEDIR + TAG, this);
	}
	
	// -----------以下3个方法用于序列化-----------------
	public User readResolve() throws ObjectStreamException, CloneNotSupportedException {
		instance = (User) this.clone();
		return instance;
	}

	private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
		ois.defaultReadObject();
	}

	public Object Clone() throws CloneNotSupportedException {
		return super.clone();
	}


	public String getAddress() {
		return address;
	}

	public String getShowAddress(){
		return address.substring(0,6)+"..."+address.substring(address.length()-4,address.length());
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getKeystore() {
		return keystore;
	}

	public void setKeystore(String keystore) {
		this.keystore = keystore;
	}

	public String getWalletName() {
		return walletName;
	}

	public void setWalletName(String walletName) {
		this.walletName = walletName;
	}

	public boolean isBackup() {
		return isBackup;
	}

	public void setBackup(boolean backup) {
		isBackup = backup;
	}

	public String getPassphrase() {
		return passphrase;
	}

	public void setPassphrase(String passphrase) {
		this.passphrase = passphrase;
	}
	public String getPinCode() {
		return pinCode;
	}

	public void setPinCode(String pinCode) {
		this.pinCode = pinCode;
	}

	public List<String> getMnemonic() {
		return mnemonic;
	}

	public void setMnemonic(List<String> mnemonic) {
		this.mnemonic = mnemonic;
	}

	public String getReferralAddress() {
		return referralAddress;
	}

	public void setReferralAddress(String referralAddress) {
		this.referralAddress = referralAddress;
	}

	public String getMyReferralAlias() {
		return myReferralAlias;
	}

	public void setMyReferralAlias(String myReferralAlias) {
		this.myReferralAlias = myReferralAlias;
	}
}
